Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/kext default action drop #1747

Merged
merged 2 commits into from
Nov 25, 2024
Merged

Conversation

vlabo
Copy link
Member

@vlabo vlabo commented Nov 20, 2024

Summary by CodeRabbit

  • New Features

    • Introduced default behavior to block and absorb packets in packet processing functions.
    • Added a new method to clear the absorb flag in the ClassifyOut struct for enhanced control.
  • Bug Fixes

    • Improved error handling for network buffer retrieval, changing logging levels for better visibility.
  • Documentation

    • Added comments to clarify the purpose of the weight field in the sublayer structure.

@vlabo vlabo requested a review from dhaavi November 20, 2024 09:54
Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request focus on enhancing packet management and control flow within the Windows kernel extension. Key updates include the introduction of default packet blocking behavior in the ale_layer_auth and ip_packet_layer functions, refined handling of verdicts and connection states, and modifications to the CalloutData struct methods to ensure the absorb flag is cleared appropriately. Additionally, a new method for clearing the absorb flag was added to the ClassifyOut struct, and comments were added for clarification in the register_sublayer function.

Changes

File Path Change Summary
windows_kext/driver/src/ale_callouts.rs - Added data.block_and_absorb() to ale_layer_auth for default packet dropping behavior.
- Refined verdict handling for connection cache.
windows_kext/driver/src/packet_callouts.rs - Added data.block_and_absorb() to ip_packet_layer for default packet blocking.
- Updated fragment handling and error logging.
windows_kext/wdk/src/filter_engine/callout_data.rs - Added clear_absorb_flag call to action_permit, action_continue, action_block, and action_none methods.
- Removed parmit_and_absorb method.
windows_kext/wdk/src/filter_engine/classify.rs - Added clear_absorb_flag method to ClassifyOut struct.
windows_kext/wdk/src/filter_engine/ffi.rs - Added comment clarifying the purpose of the weight field in the register_sublayer function.

Possibly related PRs

  • Fix reading only the needed TCP/UDP header bytes #1730: The changes in this PR involve modifications to packet handling, specifically in the packet_util.rs file, which aligns with the changes made to the ip_packet_layer function in the packet_callouts.rs file of the main PR, as both involve packet processing logic and error handling related to network packets.

Suggested reviewers

  • dhaavi

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
windows_kext/wdk/src/filter_engine/classify.rs (1)

83-86: LGTM! Consider enhancing the documentation.

The implementation correctly clears the absorb flag using bitwise operations. The method complements the existing set_absorb functionality, providing a clean way to manage the absorb flag state.

Consider expanding the documentation to match the detail level of other methods, explaining when this should be called:

-    // Removes the absorb flag.
+    // Removes the absorb flag. This should be called when packet reinjection is no longer needed
+    // or to ensure the packet continues through the network stack.
windows_kext/wdk/src/filter_engine/callout_data.rs (1)

Line range hint 188-193: Consider adding documentation for the block_and_absorb method

The implementation looks good and provides explicit control over the absorb flag. Consider adding documentation to explain:

  • The purpose of combining block and absorb actions
  • When this method should be used vs. regular block
  • The significance of the operation order (block then absorb)
+    /// Blocks the current operation and sets the absorb flag.
+    /// This combination is typically used when you want to both block the operation
+    /// and prevent further processing of the packet in the filter pipeline.
     pub fn block_and_absorb(&mut self) {
         unsafe {
             (*self.classify_out).action_block();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 38e9e34 and 59b9ae0.

📒 Files selected for processing (5)
  • windows_kext/driver/src/ale_callouts.rs (1 hunks)
  • windows_kext/driver/src/packet_callouts.rs (2 hunks)
  • windows_kext/wdk/src/filter_engine/callout_data.rs (1 hunks)
  • windows_kext/wdk/src/filter_engine/classify.rs (1 hunks)
  • windows_kext/wdk/src/filter_engine/ffi.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • windows_kext/wdk/src/filter_engine/ffi.rs
🔇 Additional comments (4)
windows_kext/wdk/src/filter_engine/callout_data.rs (1)

164-164: Verify the impact of always clearing the absorb flag

The implementation consistently clears the absorb flag after each action (permit, continue, block, none). While the pattern is implemented correctly, please verify that:

  1. Clearing the absorb flag after every action aligns with the Windows Filtering Platform (WFP) expectations
  2. There are no edge cases where we might want to preserve the absorb flag state

Also applies to: 171-171, 178-178, 185-185

windows_kext/driver/src/packet_callouts.rs (2)

113-114: Ensure legitimate packets are explicitly permitted after default blocking

With the addition of data.block_and_absorb(); at the start of the ip_packet_layer function, all packets are now blocked by default. Please verify that the subsequent logic correctly identifies and permits legitimate packets by calling data.action_permit(); to avoid unintended packet drops.


153-153: Confirm necessity of changing log level to err!

The log message has been changed from dbg! to err! in crate::err!("failed to get key from nbl: {}", err);. Confirm that this condition is severe enough to warrant error-level logging, or if it should remain at the debug level to prevent excessive logging during normal operation.

windows_kext/driver/src/ale_callouts.rs (1)

108-109: Ensure all code paths override the default block-and-absorb action

By adding data.block_and_absorb() at the beginning of ale_layer_auth, the default behavior is now to block and absorb packets unless explicitly overridden. Please verify that all code paths appropriately override this default action with data.action_permit() or data.action_block() where necessary, to prevent unintended packet drops.

@vlabo vlabo merged commit fe070b4 into develop Nov 25, 2024
5 checks passed
@vlabo vlabo deleted the feature/kext-default-action-drop branch November 25, 2024 12:03
vlabo added a commit that referenced this pull request Nov 28, 2024
* [windows_kext] Make default action to drop

* [windows_kext] Minor improvments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants